package com.ruoyi.enterprise.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.enterprise.domain.EProfession;
import com.ruoyi.enterprise.service.IEProfessionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位信息Controller
 *
 * @author JYW
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/enterprise/profession")
public class EProfessionController extends BaseController
{
    @Autowired
    private IEProfessionService eProfessionService;

    /**
     * 查询职位信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:list')")
    @GetMapping("/list")
    public TableDataInfo list(EProfession eProfession)
    {
        startPage();
        List<EProfession> list = eProfessionService.selectEProfessionList(eProfession);
        return getDataTable(list);
    }

    /**
     * 导出职位信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:export')")
    @Log(title = "职位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EProfession eProfession)
    {
        List<EProfession> list = eProfessionService.selectEProfessionList(eProfession);
        ExcelUtil<EProfession> util = new ExcelUtil<EProfession>(EProfession.class);
        util.exportExcel(response, list, "职位信息数据");
    }

    /**
     * 获取职位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eProfessionService.selectEProfessionById(id));
    }

    /**
     * 新增职位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:add')")
    @Log(title = "职位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EProfession eProfession)
    {
        return toAjax(eProfessionService.insertEProfession(eProfession));
    }

    /**
     * 修改职位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:edit')")
    @Log(title = "职位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EProfession eProfession)
    {
        return toAjax(eProfessionService.updateEProfession(eProfession));
    }

    /**
     * 删除职位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:profession:remove')")
    @Log(title = "职位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eProfessionService.deleteEProfessionByIds(ids));
    }
}
